package business.global.pk.tdk;

import java.util.*;
import java.util.stream.Collectors;

import business.global.config.GameListConfigMgr;
import com.ddm.server.common.CommLogD;
import com.ddm.server.common.utils.Txt2Utils;
import core.server.tdk.TDKAPP;
import lombok.Data;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 	吹牛 配置文件
 * @author zaf
 * */
@Data
public class TDKConfigMgr {
	public static final String fileName = "TDKConfig.txt";
	public static final String filePath = "conf/";
	private Map<String, String> configMap = new HashMap<String, String>();
	private int God_Card ;
	private int Send_End;
	private ArrayList<Integer> Private_Card1;
	private ArrayList<Integer> Private_Card2;
	private ArrayList<Integer> Private_Card3;
	private ArrayList<Integer> Private_Card4;
	private ArrayList<Integer> Private_Card5;
	private ArrayList<Integer> Private_Card6;
	private ArrayList<Integer> Private_Card7;
	private ArrayList<Integer> Private_Card8;
	private ArrayList<Integer> Private_Card9;
	private ArrayList<Integer> Private_Card10;
	private int debug ;
	private List<Integer> debugUsers = new ArrayList<>(); //GM
	private List<List<Integer>> privateCards = new ArrayList<>(); //神牌卡组
	private List<Integer> pidList = new ArrayList<>();

	public TDKConfigMgr(){
		try {
			this.configMap = Txt2Utils.txt2Map(filePath, fileName, "GBK");
			if (MapUtils.isEmpty(this.configMap) || !configMap.containsKey("God_Card")){
				return;
			}
			this.God_Card = Integer.valueOf(this.configMap.get("God_Card"));
			this.Send_End = Integer.valueOf(this.configMap.get("Send_End"));

			this.Private_Card1 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card1"));
			this.Private_Card2 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card2"));
			this.Private_Card3 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card3"));
			this.Private_Card4 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card4"));
			this.Private_Card5 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card5"));
			this.Private_Card6 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card6"));
			this.Private_Card7 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card7"));
			this.Private_Card8 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card8"));
			this.Private_Card9 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card9"));
			this.Private_Card10 = Txt2Utils.String2ListInteger(this.configMap.get("Private_Card10"));

			this.pidList = this.configMap.containsKey("pidList") ? Txt2Utils.String2ListInteger(this.configMap.get("pidList")) : new ArrayList<>();
			String pidStr = GameListConfigMgr.getInstance().getPidList(TDKAPP.gameTypeId);
			if (!StringUtils.isEmpty(pidStr)) {
				this.pidList.addAll(Txt2Utils.String2ListInteger("["+pidStr+"]"));
			}

			this.debug = Integer.parseInt(this.configMap.get("debug"));//是否开启调试模式
			this.debugUsers.addAll(Txt2Utils.String2ListInteger(this.configMap.get("debug_User")));
			this.privateCards = this.configMap.entrySet().stream().sorted((x,y) -> {
						String A = Objects.isNull(x.getKey()) ? "" : x.getKey();
						String B = Objects.isNull(y.getKey()) ? "" : y.getKey();
						return Integer.compare(A.compareTo(B), 0);
					})
					.filter(x -> x.getKey().startsWith("Private_Card"))
					.map(x -> Txt2Utils.String2ListInteger(x.getValue()))
					.collect(Collectors.toList());
		}catch (Exception e){
			CommLogD.error("TDKConfigMgr error", e);
		}

	}


	/**
	 * @return god_Card
	 */
	public boolean isGodCard() {
		return God_Card == 1;
	}
	/**
	 * @return Snd_End
	 */
	public boolean isSendEnd() {
		return Send_End == 1;
	}

	/**
	 * @return god_Card
	 */
	public boolean isDebug() {
		return debug == 1;
	}


	public boolean isDebugUser(long pid){
		return this.getDebugUsers().stream().anyMatch(x -> x == pid);
	}

	public boolean isGodUser(long pid){
		return this.getPidList().stream().anyMatch(x -> x == pid);
	}
}
